using System.Collections;
using System.Threading;
using UnityEngine;
using UnityEngine.SceneManagement;

/// <summary>
/// 场景退出逻辑
/// </summary>
public class SceneExit : MonoBehaviour
{
    [Tooltip("需要切换到的新场景名称")]
    public string newSceneName;
    public float timer = 1f; //多久生效
    private Collider2D coll;

    private void Start() {
        AudioManager.Instance.PlaySFX("启动");
        coll = GetComponent<Collider2D>();
        coll.enabled = false;
        Invoke(nameof(SetCollider), timer);
    }

    void SetCollider(){
        coll.enabled = true;
    }

    // 触发器碰撞检测
    private void OnTriggerEnter2D(Collider2D other)
    {
        if (other.CompareTag("Player"))
        {
            AudioManager.Instance.PlaySFX("传送");
            TransitionInternal();
        }
    }

    // 设置内部切换逻辑
    public void TransitionInternal()
    {
        SceneLoader.Instance.TransitionToScene(newSceneName);
    }
}
